package nf.com.crud.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.InputStream;

public class JsonUtils {
    public static String write(Object data){
        ObjectMapper objectMapper=new ObjectMapper();
        String valueAsString=null;
        try {
            valueAsString= objectMapper.writeValueAsString(data);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return valueAsString;
    }
    public static <T> T read(InputStream stream,Class<T> vo){
        ObjectMapper objectMapper=new ObjectMapper();
        T result=null;
        try {
            result=objectMapper.readValue(stream,vo);
        } catch (IOException e){
            e.printStackTrace();
        }
        return result;
    }
}
